package xian.woniuxy.be.web;

import org.apache.shiro.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import xian.woniuxy.be.entity.Contactrecord;
import xian.woniuxy.be.entity.Orders;
import xian.woniuxy.be.entity.ResultVO;
import xian.woniuxy.be.service.IOrdersService;

import java.util.List;

/**
 * @author Gong
 * @time 2022/01/09 01:01:59
 */
@RestController
public class OrdersController {

    @Autowired
    private IOrdersService ordersService;

    @PostMapping("orders/delete")
    public ResultVO delete(@RequestBody String orderId){
        if (!StringUtils.hasText(orderId)){
            throw new RuntimeException("客户ID为空");
        }
        ordersService.delete(Integer.valueOf(orderId));
        return ResultVO.success("删除成功");
    }

    @PostMapping("orders/update")
    public ResultVO update(@RequestBody Orders orders){
        ordersService.update(orders);
        return ResultVO.success("修改成功");
    }

    @PostMapping("orders/findOne")
    public ResultVO findOne(@RequestBody String cusId){
        if (!StringUtils.hasText(cusId)){
            throw new RuntimeException("客户ID为空");
        }
        List<Orders> list = ordersService.findOne(Integer.valueOf(cusId));
        return ResultVO.success(list);
    }
}
